package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.OrderSetting;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/14 19:14
 * @description：
 */
public interface OrderSettingMapper extends BaseMapper<OrderSetting> {
    @Select("select order_date , number ,reservations  from  t_ordersetting  where  order_date BETWEEN #{beginDate} and #{endDate}")
    List<OrderSetting> findOrderSettingsData(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Update("UPDATE t_ordersetting  SET number=#{num}    WHERE (order_date = #{orderDate})")
    void updateOrderSetting(@Param("num") Integer num, @Param("orderDate") String orderDate);

    @Select("select  count(0) from t_ordersetting where  order_date = #{orderDate} and number > reservations")
    Integer isOrderOkByOrderDate(String orderDate);

    @Update("update t_ordersetting set reservations=reservations+1 where order_date=#{orderDate}")
    void updateReservationsByOrderDate(String orderDate);

    @Delete("DELETE FROM t_ordersetting WHERE order_date < DATE_ADD(CURDATE(),INTERVAL -1 MONTH)")
    void deleteOrderSetting();

}
